package com.bdzl.flow.controller;

import com.bdzl.flow.service.ActChkRecService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.flow.ActChkRecDO;
import com.bdzl.pub.util.param.R;
import com.bdzl.pub.vo.flow.ActChkRecVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 流程审核及流转记录表，记录订单在每一环境的审核及流转记录情况
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-12 10:14:57
 */

@Controller
@RequestMapping("/bdzl/actChkRec")
public class ActChkRecController extends BaseController {
	@Autowired
	private ActChkRecService actChkRecService;

	@GetMapping()
	String ActChkRec(){
	    return "bdzl/actChkRec/actChkRec";
	}

	/*@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ActChkRecDO> actChkRecList = actChkRecService.list(query);
		int total = actChkRecService.count(query);
		PageUtils pageUtils = new PageUtils(actChkRecList, total);
		return pageUtils;
	}*/

	@GetMapping("/add")
	String add(){
	    return "bdzl/actChkRec/add";
	}

	@GetMapping("/edit/{acrId}")
	String edit(@PathVariable("acrId") Integer acrId,Model model){
		ActChkRecDO actChkRec = actChkRecService.get(acrId);
		model.addAttribute("actChkRec", actChkRec);
	    return "bdzl/actChkRec/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody ActChkRecDO actChkRec){
		if(actChkRecService.save(actChkRec)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@PostMapping("/update")
	public R update(@RequestBody ActChkRecDO actChkRec){
		actChkRecService.update(actChkRec);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer acrId){
		if(actChkRecService.remove(acrId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] acrIds){
		actChkRecService.batchRemove(acrIds);
		return R.ok();
	}
	/**
	 * @Description: TODO 根据订单号查询当前审核流程
	 * @param odrNo 订单号
	 * @param acrNodeId 当前节点的状态
	 * @return: com.bdzl.pub.entity.flow.ActChkRecDO
	 * @Author: Ming
	 * @Date: 2021/5/17 20:15
	 */
	@ResponseBody
	@PostMapping("/getByOdrNo")
	public List<ActChkRecDO> getByOdrNo(@RequestParam("odrNo") String odrNo,@RequestParam("acrNodeId") Integer acrNodeId){
		//根据订单号查询当前审核流程
		return actChkRecService.getByOdrNo(odrNo,acrNodeId);
	}

	/**
	 * @Description: TODO 根据订单号查询所有审核流程
	 * @param odrNo 订单号
	 * @return: com.bdzl.pub.entity.flow.ActChkRecDO
	 * @Author: Ming
	 * @Date: 2021/5/17 20:15
	 */
	@PostMapping(value = "/getActChkRecByOdrNo")
	@ResponseBody
	public List<ActChkRecVO> getActChkRecByOdrNo(@RequestParam("odrNo") String odrNo){
		Map map = new HashMap<>();
		map.put("acrOdr",odrNo);
		return actChkRecService.list(map);
	}

	/**
	 * @Description: TODO 查询除自己之外的流程状态
	 * @param odrNo 订单号
	 * @param acrNodeId 当前的节点id
	 * @return: com.bdzl.pub.entity.flow.ActChkRecDO
	 * @Author: Ming
	 * @Date: 2021/5/17 20:15
	 */
	@PostMapping(value = "/getActChkRecByOdrNoNotAcrNodeId")
	@ResponseBody
	List<ActChkRecVO> getActChkRecByOdrNoNotAcrNodeId(@RequestParam("odrNo") String odrNo,@RequestParam("acrNodeId") Integer acrNodeId){
		return actChkRecService.getActChkRecByOdrNoNotAcrNodeId(odrNo,acrNodeId);
	}
}
